package com.situ.vivamarket.service.front.impl;


import com.situ.vivamarket.dao.WishlistDao;
import com.situ.vivamarket.model.front.WishlistItem;
import com.situ.vivamarket.service.front.WishlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class WishlistServiceImpl implements WishlistService {
    WishlistDao wishlistDao;
    @Autowired
    public void setWashlistDao(WishlistDao wishlistDao) {
        this.wishlistDao = wishlistDao;
    }
//  增加收藏
    @Override
    public boolean addItem(WishlistItem wishlistItem) {
        wishlistItem.setCreatedTime(LocalDateTime.now());//增加创建时间
        return this.wishlistDao.insert(wishlistItem)>0;
    }
//  查找会员所有收藏
    @Override
    public List<WishlistItem> findItemsByMemberId(Integer id) {
        return this.wishlistDao.findByMemberId(id);
    }
//  删除收藏
    @Override
    public int deleteItemById(Integer id) {
        return this.wishlistDao.deleteById(id);
    }
//    根据唯一项查找收藏

    @Override
    public WishlistItem findByUnique(WishlistItem wishlistItem) {
        return wishlistDao.findByUnique(wishlistItem);
    }
}
